import 'dart:convert';

T? asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class AuthDTO {
  AuthDTO({
    required this.id,
    required this.newPwd,
    required this.userPwd,
  });

  factory AuthDTO.fromJson(Map<String, dynamic> jsonRes) => AuthDTO(
        id: asT<int>(jsonRes['id'])!,
        newPwd: asT<String>(jsonRes['newPwd'])!,
        userPwd: asT<String>(jsonRes['userPwd'])!,
      );

  int? id;
  String? newPwd;
  String? userPwd;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'id': id,
        'newPwd': newPwd,
        'userPwd': userPwd,
      };

  AuthDTO clone() => AuthDTO.fromJson(asT<Map<String, dynamic>>(jsonDecode(jsonEncode(this)))!);
}
